package cn.szzsi._admin;

import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Member;
import cn.szzsi.common.model.UserFeedback;
import cn.szzsi.common.model.UserFeedbackReply;
import com.jfinal.aop.Clear;

import java.util.List;

/**
 * Created by haotian on 2016/12/8.
 */
public class UserFeedBackReplyController extends BaseAdminController<UserFeedback> {
    private String path;
    private String shopId;
    public void reply(){
        String feedbackId=getPara("feedbackId");
        UserFeedback userFeedBack= UserFeedback.dao.findById(feedbackId);
        setAttr("userFeedBack",userFeedBack);
        render(CommonUtil.TEMPLATE_PATH+"/business/customerservice/user_feedback_reply.html");
    }
    public void raplysave(){
        shopId=getAttr("shopId");
        String feedbackId=getPara("feedbackId");//用户反馈i
        if(UserFeedbackReply.dao.getByFeedbackId(Integer.valueOf(feedbackId))!=null){
            renderJson(Msg.fail("该条反馈已回复哦!",""));
            return;
        }
        String content=getPara("content");
        UserFeedbackReply.dao.saveInfo(content,feedbackId,shopId,getLoginMember());
        UserFeedback.dao.findById(feedbackId).set("status",1).update();//改变反馈记录状态(状态:0-未回复,1-已回复);
        renderJson(Msg.SUCCESS);

    }

    //ajax list
    public void ajaxlist(){
        shopId=getAttr("shopId");
        List<UserFeedback> lub = UserFeedback.dao.find("select * from mall_user_feedback where uid = ? order by createDate desc",shopId);
        renderJson(lub);
    }

    @Clear
    public void save(){
        String uid=getPara("shopId");
        String content=getPara("content");
        String name=getPara("name");
        String phone=getPara("phone");
        UserFeedback.dao.saveInfo(content,name,phone,uid,getLoginMember());
        renderJson(Msg.SUCCESS);;

    }

    public void record(){
        Integer feedbackId=getParaToInt("feedbackId");
        UserFeedback userFeedBack= UserFeedback.dao.findById(feedbackId);
        setAttr("userFeedBack",userFeedBack);

        //查询回复内容信息
        UserFeedbackReply userFeedBackReply= UserFeedbackReply.dao.getByFeedbackId(feedbackId);
        setAttr("userFeedBackReply",userFeedBackReply);

        //查询回复者信息
        Member member= Member.dao.findById(userFeedBackReply.getStr("replier"));
        setAttr("username",member.getStr("username"));

        render(CommonUtil.TEMPLATE_PATH+"/business/customerservice/user_feedback_detail.html");
    }
}
